package com.bootdo.app.service.impl;

import com.bootdo.app.common.utils.ContextHandlerUtil;
import com.bootdo.app.dao.BackGroundMapper;
import com.bootdo.app.service.BackGroundService;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.ShiroUtils;
import com.bootdo.system.domain.TbWxBackGround;
import com.bootdo.system.domain.TbWxuser;
import com.bootdo.system.domain.UserDO;
import com.bootdo.system.mapper.TbWxuserMapper;
import com.bootdo.system.service.WxUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * @create 2021-02-27 16-29
 */
@Service
public class BackGroundServiceImpl implements BackGroundService {

    @Autowired
    private BackGroundMapper backGround;

    @Autowired
    private TbWxuserMapper wxUser;


    @Override
    public List selectAdminBackGround(int backType) {
        String currentUserId = ContextHandlerUtil.getCurrentUserId();
        TbWxuser tbWxuser = wxUser.selectByPrimaryKey(Integer.valueOf(currentUserId));
        String sid = tbWxuser.getSid();
        List map = backGround.selectAdminBackGround(Long.valueOf(sid),backType);
        return map;
    }

    @Override
    public PageUtils selectBackGroundList(Query query) {
        UserDO user = ShiroUtils.getUser();
        query.put("adminId",user.getUserId());
        List list = backGround.selectBackGroundList(query);
        int i = backGround.selectBackGrounCount(query);
        PageUtils pageUtils = new PageUtils(list,i);
        return pageUtils;
    }

    @Override
    public void insertBackGround(Map map) {
        UserDO user = ShiroUtils.getUser();
        map.put("adminId",user.getUserId());
        //wxBackGround.setAdminId(user.getUserId());
        map.put("createTime",LocalDateTime.now().toString());
        //wxBackGround.setCreateTime(LocalDateTime.now().toString());
        backGround.insetBackGround(map);
    }

    @Override
    public void updateBackGround(Map map) {
        backGround.updateBackGround(map);
    }

    @Override
    public TbWxBackGround selectById(Long id) {
        return backGround.selectById(id);
    }
}
